import numpy as np
import matplotlib.pyplot as plt
from matplotlib.image import imread

def addData():
    # 生成数据
    x = np.arange(0, 6, 0.1)
    y1 = np.sin(x)
    y2 = np.cos(x)

    plt.plot(x, y1, label="sin(x)")
    plt.plot(x, y2, linestyle="--", label="cos(x)")  # 用虚线绘制
    plt.xlabel("x")  # x轴标签
    plt.ylabel("y")  # y轴标签
    plt.title('sin & cos')  # 标题
    plt.legend()
    plt.show()
url = 'D:\\PycharmProjects\\PythonProject\\image\\zwz.jpg'

# 显示图像
def showImage():
    img = imread(url)
    plt.imshow(img)

    plt.show()


#感知机的简单实现
# def AND(x1,x2):
#     w1,w2 ,theta = 0.5,0.5,0.7
#     tmp = x1*w1 + x2*w2
#     if tmp <= theta:
#         return 0
#     elif tmp > theta:
#         return 1


#导入权重和偏置
def AND(x1,x2):
    x = np.array([x1,x2])
    w = np.array([0.5,0.5])
    b = -0.7
    tmp = np.sum(w*x)+b
    if tmp <= 0:
        return 0
    else:
        return 1

if __name__ == '__main__':
    # 与门
    print(AND(0,0)) # 输出0
    print(AND(1,0)) # 输出0
    print(AND(0,1)) # 输出0
    print(AND(1,1)) # 输出1
